#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
#include "Tool.h"
#include "ToolBox.h"


using namespace std;
using namespace sf;

vector<Tool*> Tool::tools(0);

Tool::Tool(string imageName, bool trans) : logo(), actif(false) {
    tools.push_back(this);
    transparent = trans;
    if(!logo.LoadFromFile(imageName)){
        cout << "Impossible de charger le fichier " << imageName << endl;
    }
}

int Tool::getBorderSize(void){
    return BORDER_SIZE;
}

Shape Tool::toShape(float cote){

    return Shape::Rectangle(0,0,cote,cote,Color(80,80,80),BORDER_SIZE,Color(255,255,255));
}

vector<Tool*> Tool::getTools(void){
    return tools;
}

Sprite Tool::getLogo(void){
    Sprite sprite;
    if(transparent) {
        logo.CreateMaskFromColor(Color(255,255,255,255),0);
    }
    sprite.SetImage(logo);
    return sprite;
}

void Tool::setActif(bool etat){
    actif = etat;
}

bool Tool::isActif(void){
    return actif;
}

bool Tool::isTransparent(void) {
    return this->transparent;
}

int Tool::whoIsActif(void) {
    int toolNumber=-1;
    for(int i=0; i<(int)Tool::getTools().size(); i++) {
        if(Tool::getTools()[i]->isActif()) { // Si il est actif
            if(Tool::getTools()[i]->isTransparent() == true) { // Si il est transparent
                toolNumber = i*10;
            }
            else {
                toolNumber = i;
            }

        }
    }
    return toolNumber;
}

bool Tool::isActifIsTrans(void) {
    if(tools[whoIsActif()])
        return true;
    else
        return false;
}

